#include "AppDelegate.h"

#include "NFComm/NFRoot/NFCRoot.h"
#include "NFComm/NFPluginLoader/NFCPluginManager.h"
#include "UI/LogoDialog.h"
#include "UI/SampleDialog.h"
#include "NFComm/NFUIManager/NFCUIUtils.h"
USING_NS_CC;

#define DEFAULT_WINDOW_WIDTH (1136)
#define DEFAULT_WINDOW_HEIGHT (640)

#define MIN_WINDOW_WIDTH (1136)
#define MIN_WINDOW_HEIGHT (640)
#define MAX_WINDOW_WIDTH (1136)

#define MAX_WINDOW_HEIGHT (640)

AppDelegate::AppDelegate() {

}

AppDelegate::~AppDelegate() 
{
}

//if you want a different context,just modify the value of glContextAttrs
//it will takes effect on all platforms
void AppDelegate::initGLContextAttrs()
{
    //set OpenGL context attributions,now can only set six attributions:
    //red,green,blue,alpha,depth,stencil
    GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};

    GLView::setGLContextAttrs(glContextAttrs);
}

bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if (!glview) {
#ifdef WIN32
        glview = GLViewImpl::createWithRect("Laboratory", Rect(0, 0, DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT));
        //glview = GLViewImpl::createWithFullScreen("Laboratory");
#else
        glview = GLViewImpl::create("Laboratory");
#endif
        director->setOpenGLView(glview);
    }

    NFCUtils::SetDesignResolutionSize(Size(MAX_WINDOW_WIDTH, MAX_WINDOW_HEIGHT), Size(MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT));

    // turn on display FPS
    director->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0f / 60);

    FileUtils::getInstance()->addSearchPath("res");

    // create a scene. it's an autorelease object
    auto scene = NFCRoot::scene();
    // run
    director->runWithScene(scene);

    LogoDialog::showUI();
	// asdasdasdasdasd
	// asdasasdasdasd

    return true;
}

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground() {
    Director::getInstance()->stopAnimation();

    // if you use SimpleAudioEngine, it must be pause
    // SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground() {
    Director::getInstance()->startAnimation();

    // if you use SimpleAudioEngine, it must resume here
    // SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
}
